package ru.ifmo.trafficspy.tests;

import static org.junit.Assert.*;

import java.util.List;

import org.junit.Before;
import org.junit.Test;

import ru.ifmo.trafficspy.common.Interval;
import ru.ifmo.trafficspy.common.Item;
import ru.ifmo.trafficspy.common.Packet;
import ru.ifmo.trafficspy.provider.SimpleProvider;

public class SimpleProviderTest {

	private SimpleProvider sp;
	
	@Before
	public void setUp() throws Exception {
		sp = new SimpleProvider(100, 10, 50);
	}
	
	@Test
	public void test1() {
		for (int i = 0; i < 100; i++) {
			List<Item> res = sp.getTraffic();
			assertTrue("Length is odd", res.size() % 2 == 1);
			for (int j = 0; j < res.size(); j++) {
				if (j % 2 == 0) {
					assertTrue(String.format("Object # %d is not a packet", j), res.get(j) instanceof Packet);
				} else {
					assertTrue(String.format("Object # %d is not an interval", j), res.get(j) instanceof Interval);
				}
			}
		}
	}
	
}
